<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link href="css/index.css" rel="stylesheet" type="text/css" />
<script src="../../../js/prototype.js" type="text/javascript"></script>
<script src="../../../js/engine.js" type="text/javascript"></script>
<script src="../../../js/public.js" type="text/javascript"></script>
<title>入库单录入界面</title>
<script>
function getXHR(){
if(typeof XMLHttpRequest!="undefined")return new XMLHttpRequest();
var MSXML = 
['MSXML2.XMLHTTP.6.0','MSXML2.XMLHTTP.5.0','MSXML2.XMLHTTP.4.0','MSXML2.XMLHTTP.3.0',
'MSXML2.XMLHTTP','Microsoft.XMLHTTP'];
  for(var n = 0; n < MSXML.length; n ++){
    try{
      return new ActiveXObject(MSXML[n]);      
    }catch(e){}
  }
  return null;
}
Ajax={
	doRequest:function(url,params,callback){
		var xhr=getXHR();
	xhr.open("post",url);
	xhr.onreadystatechange=function(){		
		if(xhr.readyState==4){		
			 callback(xhr);
		}
	}
	xhr.send(params||null);		
	}
}
function addItem(){
	tb=document.getElementById("listDB");
	
	var tbody=tb.tBodies[0];
	var tr=document.createElement("tr");
	var firstTr=tbody.rows[0];
	tr.setAttribute("align","center");
	tr.setAttribute("bgcolor","#FFFFFF");
	for(var i=0;i<firstTr.cells.length;i++){
		var td=document.createElement("td");
		td.innerHTML=firstTr.cells[i].innerHTML;
		tr.appendChild(td);
		
	}
	//tr.innerHTML=tbody.rows[0].innerHTML;
	tbody.appendChild(tr);
	//alert(tb.tBodies[0].rows[0].cells[0].innerHTML);
}
function removeItem(event){	
	var tbody=document.getElementById("listDB").tBodies[0];
	if(tbody.rows.length<2){
		alert("仅有一个项,不能再删除!");
		return;
	}
	var a=event.target?event.target:event.srcElement;
	tbody.removeChild(a.parentNode.parentNode);	
}

function countTatal(){
	var tbody=document.getElementById("listDB").tBodies[0];
	var num=0,amount=0;
	for(var i=0;i<tbody.rows.length;i++){
		var tr=tbody.rows[i];
		var n=tr.cells[4].firstChild.value;
	    var a=tr.cells[5].innerHTML;		
		if(parseFloat(n))num+=parseFloat(n);
		if(parseFloat(a))amount+=parseFloat(a);
	}
	
	document.getElementById("listDB").tFoot.rows[0].cells[4].innerHTML=num;
	document.getElementById("listDB").tFoot.rows[0].cells[5].innerHTML=amount.toFixed(2);
}
function countAmount(event){
	var a=event.target?event.target:event.srcElement;
	var tr=a.parentNode.parentNode;
	var price=tr.cells[3].firstChild.value;
	var num=tr.cells[4].firstChild.value;
	var amount=price*num;
	tr.cells[5].innerHTML=amount.toFixed(2);
	countTatal();
}
function loadProduct(event,productId){
	var a=event.target?event.target:event.srcElement;
	var tr=a.parentNode.parentNode;
	Ajax.doRequest("product.do?cmd=getProduct&id="+productId,null,function(xhr){
		var s=xhr.responseText;
		var o=eval("("+s+")");
		tr.cells[1].innerHTML=o.sn;
		tr.cells[2].innerHTML=o.spec;
		tr.cells[3].firstChild.value=o.costPrice;
	});
}
window.onload=function(){
	var tbody=document.getElementById("listDB").tBodies[0];
	for(var i=0;i<tbody.rows.length-1;i++){
		var ps=tbody.rows[i].cells[0].firstChild;
		ps.value=ps.getAttribute("theValue");
	}
}
</script>
</head>
<body>
  <form id="stockIncomeForm" name="stockIncomeForm" action='stockIncome.do' method="post">
<div class="content-right">
  <div class="content-r-pic">
    <div style="margin:8px auto auto 12px;"><img src="../../../images/StockIncome.gif" width="138" height="17" /></div>
  </div>
    <html:hidden property="id"/>
    <html:hidden property="cmd" value="save"/>
    <div class="content-text">
      <div class="square-o-top">
        <table width="100%"  border="0" cellpadding="0" cellspacing="0" style="font-size:14px; font-weight:bold; font-family:"黑体";">
          <tr>
            <td width="60">定单编号:</td>
            <td width="130"><input type="text" class="baseInput" value="" name="sn" id="sn" /></td>
            <td width="60">入库日期:</td>
            <td width="150"><input name="inputDate" type="text" class="baseInput" id="inputDate" ondblclick="EasyAjaxUtil.getCalendar();" value="$!obj.inputDate" size="8" readonly/>
              <img name="btnJLDLSJ" id="btnJLDLSJ" width="14" height="16" align="absmiddle" src="../../../images/base/calendar.gif" onClick="EasyAjaxUtil.getCalendar('inputDate');" style="CURSOR:pointer"></td>
            <td width="55">供应商:</td>
            <td width="164"><select name="supplier_Id" id="supplier_Id" onchange="this.disabled=true" style="width:120px">
                <option value="">请选择...</option>
                
                
                #foreach($info in $supplierList)
                    
                
                <option value="$!info.id">$!info.name</option>
                
                
                #end
              
              
              </select></td>
            <td width="40">仓库:</td>
            <td width="156"><select name="supplier_Id" id="supplier_Id" onchange="document.getElementById('ListForm').submit()" style="width:120px">
                <option value="">请选择...</option>
                
                
                #foreach($info in $depotList)
                    
                
                <option value="$!info.id">$!info.name</option>
                
                
                #end
              
              
              </select></td>
          </tr>
        </table>
      </div>
      <div class="square-order">
        <table width="100%"  border="0" id="listDB" cellpadding="0" cellspacing="0">
          <thead>
            <tr align="center" style="background:url(images/table_bg.gif) repeat-x;">
              <td>产品</td>
              <td>编号</td>
              <td>规格</td>
              <td>价格(采购价)</td>
              <td>数量</td>
              <td>金额</td>
              <td>备注</td>
              <td><a href="#" onclick="addItem()">添加产品</a></td>
            </tr>
          </thead>
          <tbody>
          
          #foreach($obj in ${result})
          <tr align="center" bgcolor="#FFFFFF">
            <td><select  name="productsId" onchange="loadProduct(event,this.value)" theValue="${item.product.id}">
                <option value="">--请选择--</option>
                
                
         #foreach($obj in ${productList})
         
                
                <option value="${obj.id}">${obj.name}</option>
                
                
         #end
        
              
              </select></td>
            <td>${obj.product.sn}</td>
            <td>${obj.product.spec}</td>
            <td><input name="prices" type="text"  size="5" onchange="countAmount(event)" value="${obj.price}" /></td>
            <td><input name="nums" type="text" size="5" onchange="countAmount(event)"  value="${obj.num}"  /></td>
            <td>${obj.amount}&nbsp;</td>
            <td><input name="remarks" type="text" size="20" value="${obj.remark}" /></td>
            <td><img src="images/icon_04.gif" /><a class="xiu" href="#" onclick="removeItem(event)">删除</a></td>
          </tr>
          #end
          <tr align="center" bgcolor="#FFFFFF">
            <td style="width:90px"><select  name="productsId" onchange="loadProduct(event,this.value)">
                <option value="">--请选择--</option>
                
                #foreach($obj in ${supplierList})
                  
                <option value="${obj.id}">${obj.name}</option>
                
                #end
              
              </select></td>
            <td><input type="text" value="" class="baseInput" style="width:50px" /></td>
            <td><input type="text" value="" class="baseInput" style="width:50px" /></td>
            <td><input name="prices" type="text" class="baseInput" style="width:40px" onchange="countAmount(event)" /></td>
            <td><input name="nums" type="text" class="baseInput" style="width:40px" onchange="countAmount(event)"  /></td>
            <td><input type="text" value="" class="baseInput" style="width:50px" /></td>
            <td><input name="remarks" type="text" class="searchInput" style="width:150px" /></td>
            <td><img src="images/icon_04.gif" /><a class="xiu" href="#" onclick="removeItem(event)">删除</a></td>
          </tr>
          </tbody>
          
          <tfoot>
            <tr align="center" bgcolor="#FFFFFF">
              <td height="28">合计</td>
              <td>&nbsp;</td>
              <td>&nbsp;</td>
              <td>&nbsp;</td>
              <td>&nbsp;</td>
              <td>&nbsp;</td>
              <td>&nbsp;</td>
              <td>&nbsp;</td>
            </tr>
          </tfoot>
        </table>
        <div class="order-botton_1">
          <div style="margin:1px auto auto 1px;">
          <table>
              <tr>
                <td><input type="image" src="images/order_tuo.gif" border="0" /></td>
                <td>&nbsp;</td>
                <td><input type="image" src="images/order_tuo.gif" border="0" onclick="this.form.reset();return false;" /></td>
                <td>&nbsp;</td>
                <td><input type="image" src="images/order_tuo.gif" border="0" onclick="location.href='?cmd=list';return false;" /></td>
              </tr>
            </table>
          </div>
        </div>
      </div>
    </div>
  <div class="content-bbg"><img src="images/content_bbg.jpg" /></div>
</div>  </form>
</body>
</html>
